package com.example.composableexample.drawer

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.navArgument
import com.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable

/**
 * author: LiLiang
 * createTime: 2022/9/30-21:43
 * remark:
 **/

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun AppNavigator(navController: NavHostController, openDrawer: () -> Unit) {
    AnimatedNavHost(navController = navController, startDestination = AppScreens.HomeScreen.route) {
        composable(route = AppScreens.HomeScreen.route) {
            HomeScreen(navController = navController) {
                openDrawer()
            }
        }
        composable(route = AppScreens.AccountScreen.route) {
            AccountScreen(navController = navController) {
                openDrawer()
            }
        }
        composable(route = AppScreens.ContactScreen.route) {
            ContactScreen(navController = navController) {
                openDrawer()
            }
        }
        composable(route = AppScreens.HelpScreen.route) {
            HelpScreen(navController = navController) {
                openDrawer()
            }
        }
        composable(route = AppScreens.EmployeeScreen.route + "/{empId}/{isEdit}",
            arguments = listOf(
                navArgument("empId") {
                    type = NavType.StringType
                    defaultValue = ""
                },
                navArgument("isEdit") {
                    type = NavType.BoolType
                    defaultValue = false
                }
            ),
            enterTransition = {
                slideInVertically(
                    initialOffsetY = { 1800 }
                )
            },
            popExitTransition = {
                slideOutVertically(
                    targetOffsetY = { 1800 }
                )
            }
        ) {
            val isEdit = it.arguments?.getBoolean("isEdit")
            val empId = it.arguments?.getString("empId")
            AddEditEmployeeScreen(navController = navController, empId = empId, isEdit = isEdit!!)
        }
    }
}